import RPi.GPIO as GPIO
import time

# 设置 GPIO 模式为 BCM
GPIO.setmode(GPIO.BCM)

# 定义四角开关的引脚
SWITCH_PIN = 23  

GPIO.setup(SWITCH_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)

try:
    previous_state = GPIO.input(SWITCH_PIN)

    while True:
        current_state = GPIO.input(SWITCH_PIN)

        # 检测到引脚电平变化
        if current_state != previous_state:
            print("zhixing")
        # 等待一段时间后重新检测
        time.sleep(0.1)

except KeyboardInterrupt:
    print("程序被终止")

finally:
    GPIO.cleanup()  # 清理GPIO状态
